// pages/my/OrderDetails/OrderDetails.js
var pageShow = '1'//页面显示
Page({
  data: {
    text: '\n',
    ongoing:[],//进行中\
    pageShow1:true,//页面显示
  },
  onLoad: function (options) {
    var that=this; 
    this.setData({
      currentTab: 0,
    })
    wx.getStorage({
      key: 'page',
      success: function(res) {
        that.setData({
          pageShow:res.data
        })
        pageShow=res.data;
        that.order()
      },
      fail:function(res){

      }
    })
  },
    //滑动切换
    swiperTab: function (e) {
      var that = this;
      that.setData({
        currentTab: e.detail.current
      });
      //.initial('初始化数据')
      //this.currentTab()
    },
    //点击切换
    clickTab: function (e) {
      var that = this;
      if (this.data.currentTab=== e.target.dataset.current) {
        return false;
      } else {
        that.setData({
          currentTab: e.target.dataset.current
        })
        this.currentTab()
      }
    },
  //订单
  order:function(res){
    if (this.data.pageShow == 0) {
      var Url = ''
    }else if (this.data.pageShow == 1) {
      this.currentTab()
    }else if (this.data.pageShow == 2) {
      var Url = ''
    }else if (this.data.pageShow == 3) {
      var Url = ''
    }
  },
  currentTab:function(){//切换导航
    if (this.data.currentTab == 0) {
      var Url = ''
    }else if (this.data.currentTab == 1) {
      var Url = 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/json/ongoing.json';
      this.request(Url);
    }else if (this.data.currentTab == 2) {
      var Url = 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/json/hasBeenCompleted.json'
      this.request(Url);
    }else if (this.data.currentTab == 3) {
      var Url = 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/json/hasBeenCancelled.json'
      this.request(Url);
    }
  },
  request:function(Url){//网络请求
    var that = this
    var ongoing = this.data.ongoing
    var pageShow1 = this.data.pageShow1
    wx.request({
      url: Url,
      method:'GET',
      header:{
        'content-type': 'application/json'
      },
      success:function(res){
        that.setData({
          ongoing:res.data
        })
        if (Object.keys(res.data).length == 0) {
          that.setData({
            pageShow1 : false
          })
        }else{
          that.setData({
            pageShow1 : true
          })
        }
      },fail:function(res){
        console.log(res)
      }
     })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})